package com.db.query;

import java.sql.ResultSet;
import java.sql.Statement;

import com.db.connection.ConnectionToDB;

public class GetInfoFromDb {
	private static Statement statement = null;
	private static ResultSet resultSet = null;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			// Statements allow to issue SQL queries to the database
			statement = ConnectionToDB.connectToDb().createStatement();
			// Query...
			String query = "select * from onlyOne where onlyOne.id=14";

			// Result set get the result of the SQL query...
			resultSet = statement.executeQuery(query);
			System.out.println("resultSet tiene "
					+ resultSet.getMetaData().getColumnCount() + " columnas.");
			while (resultSet.next()) {
				for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
					System.out.println("Column " + i + " "
							+ resultSet.getMetaData().getColumnName(i)
							+ " --> " + resultSet.getString(i));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ConnectionToDB.closeConnection();
		}
	}
}
